package SolveQuestions;

import java.util.ArrayList;

public class JZ6 {

    class Solution {

        public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
            ArrayList<Integer> result = new ArrayList<>();

            while(listNode != null) {
                result.add(listNode.val);
                listNode = listNode.next;
            }
            int left = 0, right = result.size() - 1;
            while(left < right){
                Integer temp = result.get(left);
                result.set(left, result.get(right));
                result.set(right, temp);
                left ++;
                right --;
            }
            return result;
        }
    }

     public class ListNode {
        int val;
        ListNode next = null;
        ListNode(int val) {
            this.val = val;
        }
    }

}
